package net.xiangcaowuyu.example1;

import com.alibaba.druid.pool.DruidDataSource;
import net.xiangcaowuyu.example1.config.MyAuditorAware;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.repository.query.QueryLookupStrategy;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@SpringBootApplication
@EnableJpaRepositories(queryLookupStrategy = QueryLookupStrategy.Key.CREATE_IF_NOT_FOUND)
@EnableJpaAuditing
@EnableTransactionManagement
public class Example1Application {

    public static void main(String[] args) {
        SpringApplication.run(Example1Application.class, args);
    }

    @Bean
    public AuditorAware<String> auditorAware() {
        return new MyAuditorAware();
    }

    @Bean(name = "master")
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource.druid")
    public DataSource dateSource() {
        return new DruidDataSource();
    }
}
